<template>
  <nav class="navlist">
    <div class="logocontent fl">
      <img class="logoimg fl" src alt="暂时无图" />
    </div>
    <div class="fr navbar">
      <div v-if="!isLogin" class="before-login">
        <ul class="ullist">
          <li v-for="(item, i) in navTitle" :key="i">
            <span>{{item.title}}</span>
          </li>
        </ul>
        <div class="whitepaper">
          <span>Whitepaper</span>
        </div>
      </div>
      <div v-if="isLogin" class="after-login">
        <el-dropdown trigger="click" @command="choiceCommand">
          <span class="el-dropdown-link">
            {{userEmail}}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-wallet" command="/wallet">WALLET</el-dropdown-item>
            <el-dropdown-item icon="el-icon-s-custom" command="/account">ACCOUNT SECURIETY</el-dropdown-item>
            <el-dropdown-item icon="el-icon-circle-plus-outline" command="/kyc">KYC VERICATION</el-dropdown-item>
            <el-dropdown-item icon="el-icon-setting" command="/system">SYSTEM SETTING</el-dropdown-item>
            <el-dropdown-item icon="el-icon-download">DOWNLOAD</el-dropdown-item>
            <el-dropdown-item icon="el-icon-back" command="logout">LOGOUT</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown trigger="click">
          <el-badge :value="messageList.length" class="item">
            <i class="el-icon-message-solid"></i>
          </el-badge>
          <el-dropdown-menu slot="dropdown" v-show="messageList.length > 0">
            <el-dropdown-item class="clearfix" v-for="item in messageList" :key="item">
              <div class="mess-notification">
                <p v-if="item.token === 1000">AQ：{{item.amont}}Transferred</p>
                <p v-if="item.token === 1001">USDT：{{item.amont}}Transferred</p>                
                <span>{{item.time}}</span>
              </div>
            </el-dropdown-item>
            <el-dropdown-item class="clearfix">
              <div class="mess-more">More</div>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          English
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">English</el-dropdown-item>
          <el-dropdown-item command="b">Chinese</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </nav>
</template>

<script>
import { mapGetters } from "vuex";
import { noticelist } from "@/api/kycAttest"
import { hideMobileInfo, hideEmailInfo } from "@/filter/index";
export default {
  name: "navhead",
  data() {
    return {
      myHerf: "https://agent.ructrip.com/login",
      navTitle: [
        {
          title: "Home",
          path: ""
        },
        {
          title: "About Us",
          path: ""
        },
        {
          title: "Roadmap",
          path: ""
        },
        {
          title: "Core Team",
          path: ""
        },
        {
          title: "Events",
          path: ""
        }
      ],
      messageList: [],
      userEmail: "",
      activeIndex: "handleSelect"
    };
  },
  computed: {
    ...mapGetters({
      isLogin: "isLogin",
      someinfo: "someinfo"
    })
  },
  created() {
    this.$nextTick(() => {
      if (this.someinfo) {      
        if (this.someinfo.phone) {
          this.userEmail = hideMobileInfo(this.someinfo.phone); 
        } else {
          this.userEmail = hideEmailInfo(this.someinfo.email); 
        }
        this.noticelist()
      }
    })
  },
  methods: {
    handleCommand(command) {
      console.log(command);
    },
    choiceCommand(path) {
      console.log(path, 'path')
      if (path === 'logout') {
        this.$store.dispatch('resetToken').then(() => {
          location.reload()
        })
      } else {
        this.$router.push({
          path: path
        });
      }
    },
    handleSelect() {},
    /**
     * @name: 消息列表
     * ----------------
     * @test: test font
     * @msg: 
     * @param {type} 
     * @return: 
     */
    async noticelist() {
      let param = {
        notice_type: '02'
      }
      let { data } = await noticelist(param)
      if (data) {
        this.messageList = data
      }
    },
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" soped>
.navlist {
  width: 100%;
  height: 76px;
  padding: 36px 80px 0;
  box-sizing: border-box;
  color: #fff;
  .logocontent {
    width: auto;
    height: 40px;
    .logoimg {
      width: 189px;
      height: 40px;
      display: inline-block;
    }
  }
  .navbar {
    height: 22px;
    font-size: 16px;
    font-family: PingFangSC-Medium;
    font-weight: 500;
    color: #fff;
    .before-login {
      display: inline-block;
      .ullist {
        display: inline-block;
        li {
          margin-left: 45px;
          text-align: center;
          cursor: pointer;
          display: inline-block;
          span {
            line-height: 22px;
          }
        }
      }
      .whitepaper {
        display: inline-block;
        margin: 0 20px;
        background: #fff;
        width: 120px;
        cursor: pointer;
        text-align: center;
        color: #fab372;
        border-radius: 12px;
      }
    }
    .after-login {
      color: #fff;
      height: 40px;
      display: inline-block;
      .el-menu-demo {
        background: #ffaf46;
        .el-submenu {
          height: 40px;
          line-height: 40px;
        }
      }
    }
    .el-dropdown {
      color: #fff;
      cursor: pointer;
      margin: 0 20px;
    }
  }
}
</style>
<style lang="less">
.mess-notification {
  width: 220px;
  border-bottom: 1px solid #cacaca;
  p {
    color: #000;
    font-weight: 600;
    font-size: 12px;
    height: 20px;
  }
  span {
    font-size: 10px;
  }
}
.mess-more {
  color: aqua;
  width: 218px;
  text-align: center;
}
</style>